package cn.jetpiece.cloud.pay.app.core.handler;

import cn.jetpiece.cloud.core.context.LoginUserContext;
import cn.jetpiece.cloud.datasource.core.metadata.JetpieceMetaObjectHandler;

/**
 * 数据自动填充
 * @author XuJZ
 */
public class PayMateObjectHandler extends JetpieceMetaObjectHandler {

    @Override
    protected Long getUserUniqueId() {
        LoginUserContext loginUserContext = LoginUserContext.getInstance();
        if (loginUserContext == null){
            return 0L;
        }
        String token = loginUserContext.getToken(false);
        if (token == null) {
            return 0L;
        }
        return LoginUserContext.getInstance().getUserId();
    }

    /**
     * 获取用户名
     */
    @Override
    protected String getUsername() {
        LoginUserContext loginUserContext = LoginUserContext.getInstance();
        if (loginUserContext == null){
            return null;
        }
        String token = loginUserContext.getToken(false);
        if (token == null) {
            return null;
        }
        return LoginUserContext.getInstance().getUsername();
    }

    /**
     * 获取逻辑删除字段的默认值
     */
    @Override
    protected Long getDefaultTenantIdValue() {
        return 0L;
    }
}
